/*     */ package com.jcraft.jzlib;
/*     */ 
/*     */ 
/*     */ 
/*     */ final class Inflate
/*     */ {
/*     */   private static final int MAX_WBITS = 15;
/*     */   
/*     */ 
/*     */   private static final int PRESET_DICT = 32;
/*     */   
/*     */ 
/*     */   static final int Z_NO_FLUSH = 0;
/*     */   
/*     */ 
/*     */   static final int Z_PARTIAL_FLUSH = 1;
/*     */   
/*     */ 
/*     */   static final int Z_SYNC_FLUSH = 2;
/*     */   
/*     */ 
/*     */   static final int Z_FULL_FLUSH = 3;
/*     */   
/*     */ 
/*     */   static final int Z_FINISH = 4;
/*     */   
/*     */ 
/*     */   private static final int Z_DEFLATED = 8;
/*     */   
/*     */ 
/*     */   private static final int Z_OK = 0;
/*     */   
/*     */ 
/*     */   private static final int Z_STREAM_END = 1;
/*     */   
/*     */ 
/*     */   private static final int Z_NEED_DICT = 2;
/*     */   
/*     */   private static final int Z_ERRNO = -1;
/*     */   
/*     */   private static final int Z_STREAM_ERROR = -2;
/*     */   
/*     */   private static final int Z_DATA_ERROR = -3;
/*     */   
/*     */   private static final int Z_MEM_ERROR = -4;
/*     */   
/*     */   private static final int Z_BUF_ERROR = -5;
/*     */   
/*     */   private static final int Z_VERSION_ERROR = -6;
/*     */   
/*     */   private static final int METHOD = 0;
/*     */   
/*     */   private static final int FLAG = 1;
/*     */   
/*     */   private static final int DICT4 = 2;
/*     */   
/*     */   private static final int DICT3 = 3;
/*     */   
/*     */   private static final int DICT2 = 4;
/*     */   
/*     */   private static final int DICT1 = 5;
/*     */   
/*     */   private static final int DICT0 = 6;
/*     */   
/*     */   private static final int BLOCKS = 7;
/*     */   
/*     */   private static final int CHECK4 = 8;
/*     */   
/*     */   private static final int CHECK3 = 9;
/*     */   
/*     */   private static final int CHECK2 = 10;
/*     */   
/*     */   private static final int CHECK1 = 11;
/*     */   
/*     */   private static final int DONE = 12;
/*     */   
/*     */   private static final int BAD = 13;
/*     */   
/*     */   int mode;
/*     */   
/*     */   int method;
/*     */   
/*  83 */   long[] was = new long[1];
/*     */   
/*     */   long need;
/*     */   
/*     */   int marker;
/*     */   
/*     */   int nowrap;
/*     */   
/*     */   int wbits;
/*     */   InfBlocks blocks;
/*     */   
/*     */   int inflateReset(ZStream z)
/*     */   {
/*  96 */     if ((z == null) || (z.istate == null)) {
/*  97 */       return -2;
/*     */     }
/*  99 */     z.total_in = (z.total_out = 0L);
/* 100 */     z.msg = null;
/* 101 */     z.istate.mode = (z.istate.nowrap != 0 ? 7 : 0);
/* 102 */     z.istate.blocks.reset(z, null);
/* 103 */     return 0;
/*     */   }
/*     */   
/*     */   int inflateEnd(ZStream z) {
/* 107 */     if (this.blocks != null)
/* 108 */       this.blocks.free(z);
/* 109 */     this.blocks = null;
/*     */     
/* 111 */     return 0;
/*     */   }
/*     */   
/*     */   int inflateInit(ZStream z, int w) {
/* 115 */     z.msg = null;
/* 116 */     this.blocks = null;
/*     */     
/*     */ 
/* 119 */     this.nowrap = 0;
/* 120 */     if (w < 0) {
/* 121 */       w = -w;
/* 122 */       this.nowrap = 1;
/*     */     }
/*     */     
/*     */ 
/* 126 */     if ((w < 8) || (w > 15)) {
/* 127 */       inflateEnd(z);
/* 128 */       return -2;
/*     */     }
/* 130 */     this.wbits = w;
/*     */     
/* 132 */     z.istate.blocks = new InfBlocks(z, z.istate.nowrap != 0 ? null : this, 
/* 133 */       1 << w);
/*     */     
/*     */ 
/* 136 */     inflateReset(z);
/* 137 */     return 0;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   int inflate(ZStream z, int f)
/*     */   {
/* 144 */     if ((z == null) || (z.istate == null) || (z.next_in == null))
/* 145 */       return -2;
/* 146 */     f = f == 4 ? -5 : 0;
/* 147 */     int r = -5;
/*     */     for (;;)
/*     */     {
/* 150 */       switch (z.istate.mode)
/*     */       {
/*     */       case 0: 
/* 153 */         if (z.avail_in == 0)
/* 154 */           return r;
/* 155 */         r = f;
/*     */         
/* 157 */         z.avail_in -= 1;
/* 158 */         z.total_in += 1L;
/* 159 */         if (((z.istate.method = z.next_in[(z.next_in_index++)]) & 0xF) != 8) {
/* 160 */           z.istate.mode = 13;
/* 161 */           z.msg = "unknown compression method";
/* 162 */           z.istate.marker = 5;
/*     */ 
/*     */         }
/* 165 */         else if ((z.istate.method >> 4) + 8 > z.istate.wbits) {
/* 166 */           z.istate.mode = 13;
/* 167 */           z.msg = "invalid window size";
/* 168 */           z.istate.marker = 5;
/*     */         }
/*     */         else {
/* 171 */           z.istate.mode = 1;
/*     */         }
/*     */         break;
/* 174 */       case 1:  if (z.avail_in == 0)
/* 175 */           return r;
/* 176 */         r = f;
/*     */         
/* 178 */         z.avail_in -= 1;
/* 179 */         z.total_in += 1L;
/* 180 */         int b = z.next_in[(z.next_in_index++)] & 0xFF;
/*     */         
/* 182 */         if (((z.istate.method << 8) + b) % 31 != 0) {
/* 183 */           z.istate.mode = 13;
/* 184 */           z.msg = "incorrect header check";
/* 185 */           z.istate.marker = 5;
/*     */ 
/*     */ 
/*     */         }
/* 189 */         else if ((b & 0x20) == 0) {
/* 190 */           z.istate.mode = 7;
/*     */         }
/*     */         else {
/* 193 */           z.istate.mode = 2;
/*     */         }
/*     */         break;
/* 196 */       case 2:  if (z.avail_in == 0)
/* 197 */           return r;
/* 198 */         r = f;
/*     */         
/* 200 */         z.avail_in -= 1;
/* 201 */         z.total_in += 1L;
/* 202 */         z.istate.need = ((z.next_in[(z.next_in_index++)] & 0xFF) << 24 & 0xFF000000);
/* 203 */         z.istate.mode = 3;
/*     */       
/*     */       case 3: 
/* 206 */         if (z.avail_in == 0)
/* 207 */           return r;
/* 208 */         r = f;
/*     */         
/* 210 */         z.avail_in -= 1;
/* 211 */         z.total_in += 1L;
/* 212 */         z.istate.need += ((z.next_in[(z.next_in_index++)] & 0xFF) << 16 & 0xFF0000);
/* 213 */         z.istate.mode = 4;
/*     */       
/*     */       case 4: 
/* 216 */         if (z.avail_in == 0)
/* 217 */           return r;
/* 218 */         r = f;
/*     */         
/* 220 */         z.avail_in -= 1;
/* 221 */         z.total_in += 1L;
/* 222 */         z.istate.need += ((z.next_in[(z.next_in_index++)] & 0xFF) << 8 & 0xFF00);
/* 223 */         z.istate.mode = 5;
/*     */       
/*     */       case 5: 
/* 226 */         if (z.avail_in == 0)
/* 227 */           return r;
/* 228 */         r = f;
/*     */         
/* 230 */         z.avail_in -= 1;
/* 231 */         z.total_in += 1L;
/* 232 */         z.istate.need += (z.next_in[(z.next_in_index++)] & 0xFF);
/* 233 */         z.adler = z.istate.need;
/* 234 */         z.istate.mode = 6;
/* 235 */         return 2;
/*     */       case 6: 
/* 237 */         z.istate.mode = 13;
/* 238 */         z.msg = "need dictionary";
/* 239 */         z.istate.marker = 0;
/* 240 */         return -2;
/*     */       
/*     */       case 7: 
/* 243 */         r = z.istate.blocks.proc(z, r);
/* 244 */         if (r == -3) {
/* 245 */           z.istate.mode = 13;
/* 246 */           z.istate.marker = 0;
/*     */         }
/*     */         else {
/* 249 */           if (r == 0) {
/* 250 */             r = f;
/*     */           }
/* 252 */           if (r != 1) {
/* 253 */             return r;
/*     */           }
/* 255 */           r = f;
/* 256 */           z.istate.blocks.reset(z, z.istate.was);
/* 257 */           if (z.istate.nowrap != 0) {
/* 258 */             z.istate.mode = 12;
/*     */           }
/*     */           else
/* 261 */             z.istate.mode = 8;
/*     */         }
/*     */         break;
/* 264 */       case 8:  if (z.avail_in == 0)
/* 265 */           return r;
/* 266 */         r = f;
/*     */         
/* 268 */         z.avail_in -= 1;
/* 269 */         z.total_in += 1L;
/* 270 */         z.istate.need = ((z.next_in[(z.next_in_index++)] & 0xFF) << 24 & 0xFF000000);
/* 271 */         z.istate.mode = 9;
/*     */       
/*     */       case 9: 
/* 274 */         if (z.avail_in == 0)
/* 275 */           return r;
/* 276 */         r = f;
/*     */         
/* 278 */         z.avail_in -= 1;
/* 279 */         z.total_in += 1L;
/* 280 */         z.istate.need += ((z.next_in[(z.next_in_index++)] & 0xFF) << 16 & 0xFF0000);
/* 281 */         z.istate.mode = 10;
/*     */       
/*     */       case 10: 
/* 284 */         if (z.avail_in == 0)
/* 285 */           return r;
/* 286 */         r = f;
/*     */         
/* 288 */         z.avail_in -= 1;
/* 289 */         z.total_in += 1L;
/* 290 */         z.istate.need += ((z.next_in[(z.next_in_index++)] & 0xFF) << 8 & 0xFF00);
/* 291 */         z.istate.mode = 11;
/*     */       
/*     */       case 11: 
/* 294 */         if (z.avail_in == 0)
/* 295 */           return r;
/* 296 */         r = f;
/*     */         
/* 298 */         z.avail_in -= 1;
/* 299 */         z.total_in += 1L;
/* 300 */         z.istate.need += (z.next_in[(z.next_in_index++)] & 0xFF);
/*     */         
/* 302 */         if ((int)z.istate.was[0] == (int)z.istate.need) break label1176;
/* 303 */         z.istate.mode = 13;
/* 304 */         z.msg = "incorrect data check";
/* 305 */         z.istate.marker = 5;
/*     */       }
/*     */     }
/*     */     label1176:
/* 309 */     z.istate.mode = 12;
/*     */     
/* 311 */     return 1;
/*     */     
/* 313 */     return -3;
/*     */     
/* 315 */     return -2;
/*     */   }
/*     */   
/*     */ 
/*     */   int inflateSetDictionary(ZStream z, byte[] dictionary, int dictLength)
/*     */   {
/* 321 */     int index = 0;
/* 322 */     int length = dictLength;
/* 323 */     if ((z == null) || (z.istate == null) || (z.istate.mode != 6)) {
/* 324 */       return -2;
/*     */     }
/* 326 */     if (z._adler.adler32(1L, dictionary, 0, dictLength) != z.adler) {
/* 327 */       return -3;
/*     */     }
/*     */     
/* 330 */     z.adler = z._adler.adler32(0L, null, 0, 0);
/*     */     
/* 332 */     if (length >= 1 << z.istate.wbits) {
/* 333 */       length = (1 << z.istate.wbits) - 1;
/* 334 */       index = dictLength - length;
/*     */     }
/* 336 */     z.istate.blocks.set_dictionary(dictionary, index, length);
/* 337 */     z.istate.mode = 7;
/* 338 */     return 0;
/*     */   }
/*     */   
/* 341 */   private static byte[] mark = { 0, 0, -1, -1 };
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   int inflateSync(ZStream z)
/*     */   {
/* 350 */     if ((z == null) || (z.istate == null))
/* 351 */       return -2;
/* 352 */     if (z.istate.mode != 13) {
/* 353 */       z.istate.mode = 13;
/* 354 */       z.istate.marker = 0; }
/*     */     int n;
/* 356 */     if ((n = z.avail_in) == 0)
/* 357 */       return -5;
/* 358 */     int p = z.next_in_index;
/* 359 */     int m = z.istate.marker;
/*     */     
/*     */ 
/* 362 */     while ((n != 0) && (m < 4)) {
/* 363 */       if (z.next_in[p] == mark[m]) {
/* 364 */         m++;
/* 365 */       } else if (z.next_in[p] != 0) {
/* 366 */         m = 0;
/*     */       } else {
/* 368 */         m = 4 - m;
/*     */       }
/* 370 */       p++;
/* 371 */       n--;
/*     */     }
/*     */     
/*     */ 
/* 375 */     z.total_in += p - z.next_in_index;
/* 376 */     z.next_in_index = p;
/* 377 */     z.avail_in = n;
/* 378 */     z.istate.marker = m;
/*     */     
/*     */ 
/* 381 */     if (m != 4) {
/* 382 */       return -3;
/*     */     }
/* 384 */     long r = z.total_in;
/* 385 */     long w = z.total_out;
/* 386 */     inflateReset(z);
/* 387 */     z.total_in = r;
/* 388 */     z.total_out = w;
/* 389 */     z.istate.mode = 7;
/* 390 */     return 0;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   int inflateSyncPoint(ZStream z)
/*     */   {
/* 401 */     if ((z == null) || (z.istate == null) || (z.istate.blocks == null))
/* 402 */       return -2;
/* 403 */     return z.istate.blocks.sync_point();
/*     */   }
/*     */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\com\jcraft\jzlib\Inflate.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */